{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 如何实现地理位置可视化的操作\n",
    "```\n",
    "\n",
    "import requests\n",
    "import time \n",
    "import json\n",
    "import xlwings as xw\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from pyecharts import Geo, Page, Style\n",
    "app = xw.App(visible=True, add_book=False)\n",
    "path = r\"D:\\全部经纬度.xlsx\"\n",
    "xb = app.books.open(path)\n",
    "rng = xb.sheets[0].range('a1:j1000').options(pd.DataFrame).value\n",
    "rng.dropna(axis=1, inplace=True, how='all')\n",
    "rng.dropna(axis=0, inplace=True, how='all')\n",
    "lat = rng.to_dict()['纬度']\n",
    "lng = rng.to_dict()['经度']\n",
    "bh = rng.to_dict()['简称']\n",
    "total_name = rng.to_dict()['公司全称']\n",
    "\n",
    "dic = {'成衣': 11,\n",
    "       '面料': 12,\n",
    "       '辅料': 13,\n",
    "       '配件': 14,\n",
    "       '鞋品': 15,\n",
    "       '印绣花': 16\n",
    "      }\n",
    "attr =  rng['简称'].tolist()\n",
    "rng['值'] = rng['类型'].map(dic)\n",
    "value = rng['值'].tolist()\n",
    "res_dic = {}\n",
    "for i in lat:\n",
    "    s = int(i)\n",
    "    res_dic[attr[s]] = [lng[i], lat[i]]\n",
    "geo = Geo(\"供应商分布图\",width=1366,height=768,title_color=\"#000\", title_pos=\"center\")  \n",
    "geo.add(\"\",attr,value,is_visualmap=True,\n",
    "        visual_range=[11, 16],\n",
    "        symbol_size=20,\n",
    "        symbol=\"pin\",\n",
    "        symbol_color=\"#FFD700\", \n",
    "        geo_cities_coords=res_dic,\n",
    "        tooltip_formatter='{b}',\n",
    "        is_piecewise=True,\n",
    "        visual_split_number=6\n",
    "       )\n",
    "geo.render('d:\\\\含有外协的分布图.html')\n",
    "style = Style(\n",
    "    title_color=\"#fff\",\n",
    "    title_pos=\"center\",\n",
    "    width=1200,\n",
    "    height=600,\n",
    "    background_color='#404a59'\n",
    "    )\n",
    "geo = Geo(\"供应商分布图\",width=1360,height=660,title_color=\"#ffffff\", title_pos=\"center\", background_color='#404a59')  \n",
    "geo.add(\"\",attr,value,is_visualmap=True,\n",
    "        get_normal_color='#404a59',\n",
    "        visual_range=[11, 16],\n",
    "        symbol_size=20,\n",
    "        symbol=\"pin\",\n",
    "        symbol_color=\"#FFD700\",\n",
    "        is_label_show=False,\n",
    "        label_formatter='{b0}',\n",
    "        label_text_color='#ffffff',\n",
    "        label_text_size = 10,\n",
    "        tooltip_formatter='{a0}',\n",
    "        geo_cities_coords=res_dic,\n",
    "        is_piecewise=True,\n",
    "        visual_split_number=6,\n",
    "        tooltip_tragger='none'\n",
    "       )\n",
    "chart = Geo(\"供应商分布图\", **style.init_style)\n",
    "chart.add(\"\", attr, value, visual_range=[0, 200],\n",
    "          visual_text_color=\"#fff\", is_legend_show=False,\n",
    "          symbol_size=15, is_visualmap=True,\n",
    "          geo_cities_coords=res_dic,\n",
    "          tooltip_formatter='{b}',\n",
    "          label_emphasis_textsize=15,\n",
    "          label_emphasis_pos='right')\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
